﻿@page
@model AdminUI.Pages.BaseData.CategoryModel
@{
    var F = Html.F();
}

@section body {
    <f:Panel ID="Panel1" BodyPadding="5" ShowBorder="false" Layout="VBox" ShowHeader="false" IsViewPort="true">
        <Items>
            <f:Grid ID="Grid1" BoxFlex="1" ShowBorder="true" ShowHeader="false" EnableTextSelection="true" EnableColumnLines="true" EnableCheckBoxSelect="false" EnableMultiSelect="false" AllowSorting="true" AllowPaging="true" IsDatabasePaging="true"
                    DataIDField="CategoryID" DataTextField="CategoryName" PageSize="@ViewBag.PageSize" RecordCount="@ViewBag.Total" DataSource="@ViewBag.DataSource"
                    OnSort="@Url.Handler("Grid_DoAction")" OnSortFields="Panel1" SortingToolTip="true" SortingCancel="true" OnPageIndexChanged="@Url.Handler("Grid_DoAction")" OnPageIndexChangedFields="Panel1">
                <Toolbars>
                    <f:Toolbar ID="Toolbar1" ToolbarAlign="Right" ItemSpace="1">
                        <Items>
                            <f:Button ID="btnAdd" IconAlign="Left" EnableDefaultState="false" IconFont="_Plus" Text="新增" OnClientClick="onAddClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnEdit" IconAlign="Left" EnableDefaultState="false" IconFont="_Edit" Text="编辑" OnClientClick="onEditClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnDelete" IconAlign="Left" EnableDefaultState="false" IconFont="TrashO" Text="删除" OnClientClick="onDeleteClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnChangeEnableUsers" IconAlign="Left" EnableDefaultState="false" IconFont="_Tag" Text="状态">
                                <Menu>
                                    <f:MenuButton ID="btnEnableUsers" Text="启用" OnClientClick="onEnableClick();"></f:MenuButton>
                                    <f:MenuButton ID="btnDisableUsers" Text="禁用" OnClientClick="onDisableClick();"></f:MenuButton>
                                </Menu>
                            </f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnRefresh" IconAlign="Left" EnableDefaultState="false" IconFont="Refresh" Text="刷新" OnClientClick="onRefreshClick();"></f:Button>
                            <f:ToolbarFill ID="ToolbarFill1"></f:ToolbarFill>
                            <f:DropDownList ID="Condition" SelectedValue="" Width="150">
                                <f:ListItem Text="== 请选择条件 ==" Value="" />
                                <f:ListItem Text="商品分类ID" Value="CategoryID" />
                                <f:ListItem Text="商品分类名称" Value="CategoryName" />
                            </f:DropDownList>
                            <f:TriggerBox ID="Keyword" ShowLabel="false" EmptyText="请输入搜索关键字" TriggerIcon="Search" OnTriggerClick="@Url.Handler("Grid_DoAction")" OnTriggerClickFields="Panel1"></f:TriggerBox>
                        </Items>
                    </f:Toolbar>
                </Toolbars>
                <Columns>
                    <f:RowNumberField HeaderText="#" TextAlign="Center" />
                    <f:RenderField HeaderText="分类ID" DataField="CategoryID" FieldType="Int" QuickSortField="true" Width="120" TextAlign="Center" />
                    <f:RenderField HeaderText="分类名称" DataField="CategoryName" Width="220" />
                    @* <f:RenderField HeaderText="租户ID" DataField="TID" FieldType="Int" Width="80" TextAlign="Right" /> *@
                    <f:RenderField HeaderText="排序" DataField="SortFlag" FieldType="Int" Width="100" TextAlign="Right" />
                    <f:RenderCheckField HeaderText="启用" DataField="IsEnable" RenderAsStaticField="true" Width="80" TextAlign="Center" />
                    @* <f:RenderField HeaderText="创建时间" DataField="CreateTime" FieldType="Date" Renderer="Date" RendererArgument="yyyy-MM-dd" Width="200" TextAlign="Center" /> *@
                </Columns>
                <PageItems>
                    <f:ToolbarSeparator></f:ToolbarSeparator>
                    <f:ToolbarText Text="每页记录数："></f:ToolbarText>
                    <f:DropDownList ID="ddlGridPageSize" Width="60" DataSource="@new int[]{10,20,30,50,100,200}" SelectedValue="@ViewBag.PageSize"
                                    OnSelectedIndexChanged="@Url.Handler("Grid_DoAction")" OnSelectedIndexChangedFields="Panel1"></f:DropDownList>
                </PageItems>
            </f:Grid>
        </Items>
    </f:Panel>

    <f:Window ID="Window1" IsModal="true" Hidden="true" Target="Top" EnableResize="true" EnableMaximize="true" EnableIFrame="true" Width="450" Height="400">
        @*<Listeners>
    <f:Listener Event="close" Handler="onWindowClose('refresh');"></f:Listener>
    </Listeners>*@
    </f:Window>
}

@section script {
    <script src="~/res/js/grid.js"></script>
    <script>
        /*
            //关闭弹窗后刷新当前页面
            function onWindowClose(actionType, actionParams) {
                var params = {
                    //nodeId: getNodeId()
                };

                if(actionType) params.actionType = actionType;
                if(actionParams) $.extend(params, actionParams);// 加入扩展参数

                F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', params); // 触发后台事件
            }
        */
        function onAddClick(event) {
            var path = "/BaseData/CategoryAdd";
            F.ui.Window1.show(path, '新增商品分类');
        }

        function onEditClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要修改的记录！');
                return;
            }

            var selectedRow = grid1.getSelectedRow();
            var path = "/BaseData/CategoryEdit?id=" + selectedRow;
            F.ui.Window1.show(path, '编辑商品分类');
        }

        function onDeleteClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要删除的记录！');
                return;
            }

            var selectedRows = grid1.getSelectedRows();
            F.confirm({
                message: '确定要删除所选记录吗？',
                target: '_top',
                ok: function () {
                    F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                        actionType: 'delete',
                        selectedIDs: selectedRows
                    });
                }
            });
        }
        function onEnableClick() {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要启用的记录！');
                return;
            }

            var selectedRows = grid1.getSelectedRows();
            F.confirm({
                message: '确定要启用所选记录吗？',
                target: '_top',
                ok: function () {
                    F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                        actionType: 'enable',
                        selectedIDs: selectedRows
                    });
                }
            });
        }

        function onDisableClick() {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要禁用的记录！');
                return;
            }

            var selectedRows = grid1.getSelectedRows();
            F.confirm({
                message: '确定要禁用所选记录吗？',
                target: '_top',
                ok: function () {
                    F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                        actionType: 'disable',
                        selectedIDs: selectedRows
                    });
                }
            });
        }
        function onRefreshClick() {
            F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1');
        }
        /*
                //枚举类型：1-AAA，2-BBB
                function renderEnumType(value, params) {
                    switch (value) {
                        case 1:
                            return "AAA";
                        case 2:
                            return "BBB";
                        default:
                            return "";
                    }
                }

                //HTML格式化
                function renderIconClass(value, params) {
                    return F.formatString('<i class="f-icon {0}" title="{0}"></i>', value);
                }
        */

    </script>
}